/**
 * @format
 * @Author: TC
 * @Date: 2025-05-04 17:54:20
 * @Last Modified by: TC
 * @Last Modified time: 2025-05-05 02:05:20
 */

import { _decorator } from "cc";
import { NATIVE } from "cc/env";
import { app } from "../../FrameWork/App";
import { BaseScene } from "../../FrameWork/Module/Component/BaseScene";
import { LoadingUI } from "../Module/Loading/LoadingUI";
const { ccclass, property } = _decorator;

/**
 * 加载场景
 * 用来处理热更、预加载等逻辑
 */
@ccclass("LoadingScene")
export class LoadingScene extends BaseScene {
    @property({ type: LoadingUI, displayName: "加载界面" })
    loadingUI: LoadingUI = null;
    protected init(): void {
        super.init();

        //启动框架
        app.start(() => {
            this._loadFrameScript(() => {
                this._checkUpdate();
            });
        });
    }

    /**
     * 加载框架脚本
     * @param cb
     */
    private _loadFrameScript(cb: Function): void {
        cb();
    }

    /**
     * 加载业务脚本
     * @param cb
     */
    private _loadScript(cb: Function): void {
        cb();
    }
    /**
     * 检查更新
     */
    private _checkUpdate(): void {
        if (NATIVE) {
            //to do
            //原生端热更新的接口
        } else {
            //H5直接开始加载资源
            this._checkComplete();
        }
    }

    /**
     * 检查更新完成
     */
    private _checkComplete(): void {
        app.log.log("检查更新完成");
        this._loadScript(() => {
            this._showLoading();
        });
    }

    /**
     * 显示加载界面
     */
    private _showLoading(): void {
        app.log.log("开始加载");
        this.loadingUI.node.active = true;
    }
}
